<?php

namespace App\Http\Controllers\SignIn;

use App\Http\Controllers\Controller;
use App\Services\SignIn\SignInService;
use Illuminate\Http\Request;
use Exception;
use think\exception\HttpException;


class SignController extends Controller
{

    /**
     * 用户签到
     * Author：刘凯
     * date：2022/10/16
     * time：18:30
     */
    public function signIn(Request $request)
    {
        $uid = $request->header('uid');
        $data = (new SignInService())->signIn($uid);
        //根据服务层返回值执行不同动作
        switch ($data) {
            case 1:
                return \App\Services\Request::fail(201, '今天已经签到过了', '');
                break;
            default:
                return \App\Services\Request::success(200, '签到成功', $data);
        }
    }

    /**
     * 获取用户签到信息bao
     * Author：刘凯
     * date：2022/10/17
     * time：09:00
     */
    public function signInfo(Request $request)
    {
        $uid = $request->header('uid');
        $date = $request->get('date');
        $data = (new SignInService())->getSignInfo($uid, $date);
        return \App\Services\Request::success(200, 'success', $data);
    }

    /**
     * 用户补签
     * Author：刘凯
     * date：2022/10/19
     * time：14:00
     */
    public function retroactive(Request $request)
    {
        $uid = $request->header('uid');
        $date = $request->post('date');
        $data = (new SignInService())->getRetroactive($uid, $date);
        switch ($data) {
            case 1:
                return \App\Services\Request::fail(201, '补签日期不能超过今天', '');
                break;
            case 2:
                return \App\Services\Request::fail(201, '积分不足', '');
                break;
            case 3:
                return \App\Services\Request::fail(201, '该天已经签到过了', $data);
                break;
            default:
                return \App\Services\Request::success(200, '补签成功', $data);
        }
    }
}
